import { UIHelper } from "./uiHelper";
import { ProjHelper_BJ54 } from "./projHelper";

let projHelper = new ProjHelper_BJ54();
let uiHelper = new UIHelper();

let inputCoord = uiHelper.addInput();
inputCoord.value = "328443.4399,345557.6179";
let btn1 = uiHelper.addBtn("localProj_bjProj");
let btn2 = uiHelper.addBtn("test");
uiHelper.addBr();
let resLabel = uiHelper.addLabel();

btn1.addEventListener("click", (e) => {
  let value = inputCoord.value;
  if (!value) throw new Error("input coordinates error");

  let sourceCoord = value.split(",").map((c) => parseFloat(c));
  // local proj => beijing54 proj
  let interCooord = projHelper.localproj_bjproj(sourceCoord as any, {
    x_0: 3109444.007744,
    y_0: 557065.040376,
    t: -1.1889672330,
    k: 0.985971406835,
  });

  // beijing54 proj => beijing54 geos
  let resCoord0 = projHelper.bjproj_bjlnglat(interCooord as any);
  let resCoord = projHelper.bjlnglat_wgslnglat(resCoord0);
  resLabel.innerText += `${resCoord.x}, ${resCoord.y} \n`;
});

btn2.addEventListener('click', e => {
  let value = inputCoord.value;
  if (!value) throw new Error("input coordinates error");

  let sourceCoord = value.split(",").map((c) => parseFloat(c));
  let resCoord = projHelper.test(sourceCoord as any);
  resLabel.innerText += `${resCoord.x}, ${resCoord.y}\n`;
});